// import { loginByUser, getUserMenu, getUserRolePermission, validateLogin, getTeacherShowTab } from "@/api/login";
import { test } from "@/api";
const user = {
  state: {
    userInfo: {}, // 个人信息
    access_token: "" // token
  },
  actions: {
    // 用户登录
    loginByUser({ commit }, user) {
      return new Promise((resolve, reject) => {
        // loginByUser(user.username, user.password, user.openId, user.imgCode)
        test()
          .then(response => {
            const data = response.data;
            if (data.data) {
              commit("SET_ACCESS_TOKEN", data.data.token);
              commit("SET_LOG_MSG", data.data);
              console.log("data");
              console.log(data);
              resolve(response);
            } else {
              reject(error);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  },
  // mutations 改变方法
  mutations: {
    SET_ACCESS_TOKEN: (state, access_token) => {
      state.access_token = access_token;
    },
    SET_LOG_MSG(state, data) {
      state.userInfo = data;
    }
  }
};
export default user;